package org.example.lock;

import java.util.concurrent.locks.ReentrantLock;

public class LockDemo {
    static int count = 0;

    public static void main(String[] args) throws InterruptedException {
        ReentrantLock lock = new ReentrantLock();

        Runnable a = () -> {
            lock.lock();
            try {
                count++;
            } finally {
                lock.unlock();
            }
        };

        for (int i = 0; i < 8; i++) {
            new Thread(a).start();
        }

        Thread.sleep(2000);
        System.out.println(count);
    }
}
